<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8" />
	<title>Document</title>
	<style type="text/css">
		div{
			width: 150px;
			height: 100px;
			border: 1px solid black;
			color: black;
		}
	</style>
</head>
<body>
  <div id="div1">
  	
  </div>	
  <br /><br />
  <input type="text" name="shuru" id="shuru" value="" />
  <input type="button" name="" id="btn" value="确定" />
</body>
<script type="text/javascript">
var div1=document.querySelector("#div1");
var txt=[];
var bijiao=[];
var dada=false;
	function random(min, max) {
				return Math.floor(Math.random() * (max - min + 1) + min);
			}
    var arr=['0','1','2','3','4','5','6','7','8','9','10','a','b','c','d','e','f','g','h','i','g','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
    div1.onclick=function(){
    	
         txt=[];
    		for (var i=0;i<4;i++) {
    	   arr[random(0,36)];
    	   txt.push(arr[random(0,37)]);
    }
    div1.innerHTML=txt.join('');
    
    btn.onclick=function(){
    	  bijiao=shuru.value;
    	 for (var j=0;j<txt.length;j++) {
//  	 	if (bijiao[j]==txt[j]) {
//  	 		dada=true;
//  	 	} 
		switch (bijiao[j]==txt[j]){
			case bijiao[0]==txt[0]:
				break;
			case bijiao[1]==txt[1]:
				break;
			case bijiao[2]==txt[2]:
				break;
			case bijiao[3]==txt[3]:
				alert(1);
				break;
			default:
				break;
		}
    	 	
    	 }
    }
   }
    	
//if (dada=true) {
//  	 		alert("登陆成功");
//  	 	}
</script>
</html>